/*************************************************
Author: will
Date: 10/18/2012
Description:
Notes: 
*************************************************/

#ifndef __CDropItem_h__
#define __CDropItem_h__

#include "CTArray.h"
#include "CItemConfig.h"
#include "MsgComm.pb.h"
#include "commclass.h"

class CDropItem : public CTCodeObject
{
public:
	CDropItem() 
    {
        Clear();
	}

	virtual ~CDropItem() 
    {
	}

    void Clear()
    {
        _iModule = 0;
        _cExpAt = -1;
        _cSilverAt = -1;
        _cGoldAt = -1;
        _cHunliAt = -1;
        _cLilianAt = -1;
        _cReputationAt = -1;
        _cEnergyAt = -1;

        _astDropItem.Clear();
    }

    CDropItem& operator+=(CDropItem& stDropItem)
    {
        for (int i = 0; i < stDropItem._astDropItem.Size(); ++i)
        {
            this->Drop(stDropItem._astDropItem[i]);
        }

        return *this;
    }

    int Size ()
    {
        return _astDropItem.Size();
    }
    CDropItemData& GetDropItemData(int iIndex)
    {
        return _astDropItem[iIndex];
    }

    void DropSilver(int iCount);
    void DropEnergy(int iCount);
    void DropGold(int iCount);
    void DropBattleExp(int iCount);
    void DropRoleExp(int iCount);
    void DropPartnerExp(int iCount, short shPartnerID);

    void DropHunli(int iCount);
    void DropLilian(int iCount);

    void DropReputation(int iCount);

    void DropItem(int iType, int iCount);
    void DropItem(unsigned int uiResID, int iType, int iCount);

    int Drop(CDropItemData& stDropItemData);

    //背包里是否有足够空间, 装下所有物品
    bool HasEnoughSpace (unsigned int uiGid);
    
    //获取掉落的物品需要占用的背包格子数
    int GetSpaceSize (CDropItemData& stDropItemData);
    int GetSpaceSize();

    //构造PB消息
    void GetPBMsg (unsigned int uiGid, ::google::protobuf::RepeatedPtrField< ::MsgGridItemInfo > & stItems);

    void SetOssModule (int iModule);

    bool Full ();
public:
    int _iModule;   //掉落物品的模块
    CTLib::CTArray<CDropItemData, MAX_DROP_ITEM_PER_TIME> _astDropItem;

private:
    char _cExpAt;
    char _cSilverAt;
    char _cGoldAt;
    char _cHunliAt;
    char _cLilianAt;
    char _cReputationAt;
    char _cEnergyAt;
};
BEGIN_CODE_CONVERT(CDropItem)
CODE_CONVERT(_astDropItem)
END_CODE_CONVERT(CDropItem)


#endif // __CDropItem_h__

